package com.tengju.user.domain.model.protocol;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.AllArgsConstructor;

@AllArgsConstructor
public enum ProtocolType {

    /**
     * 服务协议
     */
    SERVICE_PROTOCOL(1,"服务协议"),
    /**
     * 隐私政策
     */
    PRIVACY_PROTOCOL(2,"隐私政策");

    private Integer id;
    private String desc;

    @JsonValue
    public Integer getId() {
        return id;
    }

    public String getDesc() {
        return desc;
    }

    @JsonCreator
    public static ProtocolType fromId(Integer id) {
        for (ProtocolType type : values()) {
            if (type.id.equals(id)) {
                return type;
            }
        }
        return null;
    }


    public static ProtocolType fromName(String name) {
        for (ProtocolType type : values()) {
            if (type.name().equals(name)) {
                return type;
            }
        }
        return null;
    }
}
